package com.bwie.controller;

import com.bwie.common.domain.User;
import com.bwie.common.result.Result;
import com.bwie.service.SystemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @className: SystemController
 * @Description: TODO
 * @version: v1.８.0
 * @author: 安楷杰
 * @date: 2025/11/4 9:57
 */
@RestController
@RequestMapping("/system")
@CrossOrigin(origins = "*", maxAge = 3600)
public class SystemController {
    @Autowired
    public SystemService service;

    /**
     * 查询账号
     * @param account
     * @return
     */
    @GetMapping("/loginByAccount/{account}")
    public Result<User> loginByAccount(@PathVariable(value = "account") String account) {
        // 调用 Service 层处理登录逻辑（判断账号类型+校验密码）
        User loginUser = service.loginByAccount(account);

        if (loginUser != null) {
            return Result.success(loginUser, "登录成功");
        } else {
            return Result.error("账号或密码错误");
        }
    }

    /**
     * 添加账号
     */
    @PostMapping("/add")
    public Result<String> add(@RequestBody User user) {
        // 调用 Service 层处理添加逻辑
        service.add(user);
        return Result.success("添加成功");
    }

    /**
     * 查询手机号
     */
    @GetMapping("/findTel/{phone}")
    public Result<User> findTel(@PathVariable(value = "phone") String phone) {
        // 调用 Service 层处理查询逻辑
        User user = service.findTel(phone);
        return Result.success(user);
    }

}